package com.itheima.a12;

import com.itheima.a12.jdkAOP.Foo;
import com.itheima.a12.jdkAOP.InvocationHandler;

import java.lang.reflect.Method;


/**
 * @author: AirMan
 * @date: 2025/4/11 21:01
 * @description:
 */
public class $MyJdkNewProxyInstance implements Foo {

    private InvocationHandler invocationHandler;

    public $MyJdkNewProxyInstance(InvocationHandler invocationHandler){
        this.invocationHandler = invocationHandler;
    }

    @Override
    public void foo() {
//        // 1.功能增强
//        System.out.println("before...");
//        // 2.调用目标
//        new Target().foo();
        try {
            Method method = Foo.class.getMethod("foo");
            System.out.println("调用实现的代理对象中的foo方法...");
            invocationHandler.invoke(method, new Object[0]);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void bar() {
        try {
            Method method = Foo.class.getMethod("bar");
            System.out.println("调用实现的代理对象中的bar方法...");
            invocationHandler.invoke(method, new Object[0]);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }


}
